var tuc_javascript = (function(window){
    return {
        laya:Laya,
        sprite:Laya.Sprite,//容器
        stage:Laya.Stage,//画布
        texture:Laya.Texture,//UI
        brower:Laya.Browser,//浏览器的配置信息
        handler:Laya.Handler,//整合
        webgl:Laya.WebGL,//webgl信息
        stat:Laya.Stat,
        _:function(){
            var self = this;
            self.laya.init( self.brower.clientWidth , self.brower.clientHeight , self.webgl );
            self.laya.stage.alignV = self.stage.ALIGN_MIDDLE;
            self.laya.stage.alignH = self.stage.ALIGN_CENselfER;
            self.laya.stage.scaleMode = "fixedheight";
            self.laya.stage.bgColor = "#232628";
            self.laya.stage.canvasRotation = true;

            //显示调试信息
            self.stat.show();
            //**********************************************************

            self.main();
            self.createApes();
            self.createRotate();
            self.drawPentagram();
            self.drawSomething();
            // self.createRegularity();
            return self;
        },main:function(){
            var self = this;
            var ape = new self.sprite();
            self.laya.stage.addChild(ape);
            ape.loadImage("monkey2.png");
            self.laya.loader.load("monkey3.png", self.handler.create(this, function(){
                var t = self.laya.loader.getRes("monkey3.png");
                var ape = new self.sprite();
                ape.graphics.drawTexture(t, 0, 0);
                self.laya.stage.addChild(ape);
                ape.pos(200, 0);
            }));
        },createApes:function(){
            var self = this;
            // 每只猩猩距离中心点150像素
            var layoutRadius = 150;
            var radianUnit = Math.PI / 2;

            //一个窗口，如果旋转的话，就旋转这个窗口。
            var apesCtn = new self.sprite();
            self.laya.stage.addChild(apesCtn);

            // 添加4张猩猩图片
            for (var i = 0; i < 4; i++){
                var ape = new self.sprite();
                //下载图片
                ape.loadImage("monkey3.png");
                //滚动轴
                ape.pivot(55, 72);
                // 以圆周排列猩猩
                //坐标确定
                ape.pos(Math.cos(radianUnit * i) * layoutRadius, Math.sin(radianUnit * i) * layoutRadius);
                //添加到ape里面。
                apesCtn.addChild(ape);
            }
            //把画布放在中间。
            apesCtn.pos(self.laya.stage.width / 2, self.laya.stage.height / 2);
            //按帧定时
            self.laya.timer.frameLoop(1, window,function(){
                apesCtn.rotation += 1;
            },false);
        },createRotate:function(){
            var self = this;
            var scaleDelta = 0;
            //弄出一个画布
            var apesCtn = new self.sprite();
            //加载一下图片
            apesCtn.loadImage("monkey2.png");
            //确定转轴
            apesCtn.pivot(55, 72);
            //确定一下坐标
            apesCtn.pos(self.laya.stage.width / 2, self.laya.stage.height / 2);
            //添加画布上
            self.laya.stage.addChild(apesCtn);
            //定时
            self.laya.timer.frameLoop(2, window, function(){
                apesCtn.rotation += 2;
                scaleDelta += 0.02;
                var scaleValue = Math.sin(scaleDelta);
                apesCtn.scale(scaleValue, scaleValue);
            },false);
        },drawPentagram:function(){
            // 根据数据绘制路径
            var self = this;
            var canvas = new self.sprite();
            self.laya.stage.addChild(canvas);
            var path = [];
            path.push(0, -130);
            path.push(33, -33);
            path.push(137, -30);
            path.push(55, 32);
            path.push(85, 130);
            path.push(0, 73);
            path.push(-85, 130);
            path.push(-55, 32);
            path.push(-137, -30);
            path.push(-33, -33);
            canvas.graphics.drawPoly(self.laya.stage.width / 2, self.laya.stage.height / 7, path, "#ff0000");
            canvas.graphics.drawRect(self.laya.stage.width / 4, self.laya.stage.height / 7, 100,400, "#00ff00");
        },createRegularity:function(){
            //放大镜
            var self = this;
            var maskSp;
            var bg2;
            var img_url = "bg2.png";
            self.laya.loader.load(img_url, self.handler.create(this, setup));
            
            function setup(){
                var t = self.laya.loader.getRes(img_url);
                var bg = new self.sprite();
                bg.graphics.drawTexture(t, 0, 0);
                self.laya.stage.addChild(bg);

                bg2 = new self.sprite();
                bg2.graphics.drawTexture(t, 0, 0);
                self.laya.stage.addChild(bg2);
                bg2.scale(3, 3);

                //创建mask
                maskSp = new self.sprite();
                maskSp.loadImage("mask.png");
                maskSp.pivot(50, 50);

                //设置mask
                bg2.mask = maskSp;

                self.laya.stage.on("mousemove", this, onMouseMove);
            }
            function onMouseMove(){
                bg2.x = -self.laya.stage.mouseX * 2;
                bg2.y = -self.laya.stage.mouseY * 2;
                maskSp.x = self.laya.stage.mouseX;
                maskSp.y = self.laya.stage.mouseY;
            }
        },drawSomething:function(){
            var self = this;

            sp = new self.sprite();
            self.laya.stage.addChild(sp);
            //画线
            sp.graphics.drawLine(10, 58, 146, 58, "#ff0000", 3);
            //画连续直线
            sp.graphics.drawLines(176, 58, [0, 0, 39, -50, 78, 0, 117, 50, 156, 0], "#ff0000", 5);
            //画曲线
            sp.graphics.drawCurves(352, 58, [0, 0, 19, -100, 39, 0, 58, 100, 78, 0, 97, -100, 117, 0, 136, 100, 156, 0], "#ff0000", 5);
            //画矩形
            sp.graphics.drawRect(10, 166, 166, 90, "#ffff00");
            //画多边形
            sp.graphics.drawPoly(264, 166, [0, 0, 60, 0, 78.48, 57, 30, 93.48, -18.48, 57], "#ffff00");
            //画三角形
            sp.graphics.drawPoly(400, 166, [0, 100, 50, 0, 100, 100], "#ffff00");
            //画圆
            sp.graphics.drawCircle(98, 332, 50, "#00ffff");
            //画扇形
            sp.graphics.drawPie(240, 290, 100, 10, 60, "#00ffff");
        }
    }
})(window)._();